package com.whu.service;

import com.mysql.cj.util.StringUtils;
import com.whu.domain.User;
import com.whu.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Dd
 * @date 2020/11/12 - 20:25
 */
@Service
public class UserService {

    @Autowired
    private UserMapper userMapper;
    //用户注册
    public String userRegister(String name,String password){

        //用户名密码为空
        if(StringUtils.isEmptyOrWhitespaceOnly(name) )
            return "用户名为空";
        if(StringUtils.isEmptyOrWhitespaceOnly(password))
            return "用户密码为空";
        int count = userMapper.insertUser(name, password);
        if(count==1)
            return "注册成功";
        else
            return "注册失败，请重新注册";

    }




    //用户登录
    public String userLogin(String name,String password){

        List<User> users = userMapper.selectUser(name,password);
        if(users.size()==0){
            return "用户名或者密码错误，请重新登录";
        }
        else
        {
            System.out.println(users.get(0));
            return "登录成功";
        }


    }



    //查询所有的用户信息




}
